<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        html,
        body {
            height: 100%;
        }
        
        #app {
            height: 100%;
            position: relative;
            background-color: rgba(0, 0, 0, .5);
        }
        
        .shopcart {
            position: fixed;
            bottom: 0;
            background-color: white;
            width: 100%;
            padding: 10px;
            box-sizing: border-box;
        }
        
        .shopcart .btns {
            display: flex;
            justify-content: space-between;
        }
        
        .shopcart .title {
            display: flex;
            justify-content: space-between;
            font-weight: bold;
        }
        
        .shopcart .list .good {
            display: flex;
            margin: 10px 0;
        }
        
        .shopcart .list .good .imgbox {
            width: 80px;
            margin-right: 10px;
        }
        
        .shopcart .list .good .imgbox img {
            width: 100%;
        }
        
        .shopcart .list .good .text {
            flex: 1;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
        }
        
        .shopcart .list .good .text .name {
            font-weight: bold;
        }
        
        .shopcart .list .good .text .price {
            display: flex;
            justify-content: space-between;
        }
        
        .shopcart .list .good .text .price span {
            display: inline-block;
            width: 14px;
            height: 14px;
            text-align: center;
            line-height: 14px;
            background-color: lightskyblue;
            color: white;
            border-radius: 50%;
        }
        
        .shopcart .list .good .text .price span:nth-child(2) {
            color: black;
            background-color: white;
        }
        
        .empty {
            text-align: center;
            padding: 50px;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="shopcart">
            <div class="btns">
                <span @click="mysort(index)" v-for="(item , index) in btnArr" :key="index">{{item}}</span>
            </div>
            <div v-if="list.length != 0" class="list">
                <div v-for="(item,index) in list" :key="index" class="good">
                    <div class="imgbox">
                        <img :src="item.pic" alt="">
                    </div>
                    <div class="text">
                        <div class="name">{{item.name}}</div>
                        <div class="price">
                            <div>¥{{item.price}}</div>
                            <div>
                                <span @click="sub(item)">-</span>
                                <span>{{item.count}}</span>
                                <span @click="add(item)">+</span>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</body>

</html>
<script src="../vue-2.5.21.js"></script>
<script>
    var pic = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202102%2F26%2F20210226073347_50f94.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1668131440&t=6df291a148cdb21289e91211d4daea32';
    var vm = new Vue({
        el: '#app',
        data: { //负责定义响应式数据
            btnArr: ['综合排序', '距离最近', '销量最高', '筛选'],
            list: [{
                name: '秋刀鱼',
                price: 88,
                pic,
                count: 1
            }, {
                name: '大黄鱼',
                price: 777,
                pic,
                count: 2
            }, {
                name: '皮皮虾',
                price: 9,
                pic,
                count: 3
            }, ]
        },
        methods: { //负责定义方法
            add(item) {
                item.count++;
            },
            sub(item) {
                if (item.count > 1) item.count--;
            },
            clean() {
                this.list = [];
            },
            mysort(index) {
                if (index == 0) { //点击了第一个按钮
                    this.list.sort((a, b) => {
                        return a.price - b.price; // 安价格升序
                    })
                } else if (index == 2) { //点击了第三个按钮
                    this.list.sort((a, b) => {
                        return b.count - a.count; //安数量降序
                    })
                }
            }
        }
    })
</script>